package com.lastcrdg.pieview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * author：liluo
 * e-mail：lastcrazysun@163.com
 * company：cusc
 * date：2017/9/28 14:19
 * description：
 */

public class CanvasView extends View {

    private int width;
    private int height;

    public CanvasView(Context context) {
        super(context);
    }

    public CanvasView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CanvasView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);
        paint.setColor(Color.BLACK);
//        Rect rect = new Rect(-400, -400, 400,400);
        canvas.translate( width /2 , height /2);
//        canvas.drawRect(rect, paint);
//
//        for (int i = 0; i <30 ; i++) {
//            canvas.scale(0.8f, 0.8f);
//            if (i % 3 == 1){
//                paint.setColor(Color.RED);
//            }else if (i % 3 == 2){
//                paint.setColor(Color.BLUE);
//            }else {
//                paint.setColor(Color.BLACK);
//            }
//            canvas.drawRect(rect, paint);
//        }
//        canvas.drawCircle(0, 0, 400, paint);
//        canvas.drawCircle(0, 0, 380, paint);
//        canvas.drawLine(0, 380, 0, 400, paint);
//        for (int i = 0; i < 36; i++) {
//            canvas.rotate(10);
//            canvas.drawLine(0, 380, 0, 400, paint);
//        }
    }
}
